﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Accounting_MembershipFeesCollection : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadLoginInHiddenField();
            loadDDL();
            initialLoad();
            loadReceiptType();
        }
    }

    private void loadLoginInHiddenField()
    {
        if (hfLoginID.Value == "")
        {
            hfLoginID.Value = getLogin().LoginID.ToString();
        }
    }


    private Login getLogin()
    {
        Login login = new Login();

        try
        {
            if (Session["Login"] != null)
            {
                login = (Login)Session["Login"];
            }
            else if (hfLoginID.Value != "")
            {
                login = LoginManager.GetLoginByID(int.Parse(hfLoginID.Value));
            }
            else
            { Session["PreviousPage"] = HttpContext.Current.Request.Url.AbsoluteUri; Response.Redirect("../LoginPage.aspx"); }

        }
        catch (Exception ex)
        { }

        return login;
    }

    private void initialLoad()
    {
        tr_NewMember.Visible = false;
        tr_not_NewMember.Visible = false;
        btnNext.Visible = false;
        tr_RecivePayment.Visible = false;
        tr_PaymentDetails.Visible = false;
        txtDate.Text = DateTime.Today.ToString("dd-MM-yyyy");
    }
    private void loadDDL()
    {
        /*
        select * from  SubEngineeringFieldInfo;
        select * from SubCenterInfo;
        select * from MembershipEducationalInfo;
        select * from CenterInfo;
         * */

        string sql = @"
                    
SELECT [Mem_FeesYearID]
      ,[Mem_FeesYearName]
      ,[Ordering]
  FROM IEB.dbo.[Mem_FeesYear]
order by Ordering desc
                    ";

        DataSet ds = DatabaseManager.ExecSQL(sql);

        
        ddlFeesYear.Items.Clear();
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            ListItem i = new ListItem(dr["Mem_FeesYearName"].ToString(), dr["Mem_FeesYearID"].ToString());
            ddlFeesYear.Items.Add(i);
        }

    }
    protected void btnNext_Click(object sender, EventArgs e)
    {

        btnNext.Visible = false;
        tr_PaymentDetails.Visible = true;
        tr_RecivePayment.Visible = true;
        string currentYear = "2014-2015";
        string paidUpto = (ddlFeesYear.SelectedValue == "19" ? currentYear : ddlFeesYear.SelectedItem.Text);
        DataRow dr = null;


        switch (Request.QueryString["rbtnReceiptType"])
        {
            case "1":
                //New Applicant
                /*
                string sql = "";
                sql = @"INSERT [dbo].[Mem_Member] ([MemberShipNo], [MemberShipNoDigit], [Mem_MemberTypeID], [Name], [DateOfBirth], [Age], [Comn_NationalityID], [PlaceOfBrith], [MailingAddress1], [MailingAddress2], [MailingAddress3], [MailingAddress], [PermanentAddress], [PermanentAddress1], [PermanentAddress2], [PermanentAddress3], [PhoneOffice], [PhoneResidence], [Mobile], [Email], [Fax], [OtherContactInfo], [Comn_GenderID], [PresentIEBMembershipNo], [Mem_SubDivisionID], [DeclarationDate], [Mem_ApprovedCouncilMeetingID], [ScrollNo], [ReceiptDate], [CopiesOfCertificates], [CopiesOfCertificatesComment], [CopiesOfTranscripts], [CopiesOfTranscriptsComment], [PhotoEnclosed], [ProfessionalRecordEnclosed], [ProfessionalRecordEnclosedComment], [RecomendationOffice], [RecomenDationCommentOffice], [AgeMembershipSection], [Education], [Exprerience], [RecomendationMembershipSec], [RecomenDationCommentMembershipSec], [MembershipSectionEmployeeID], [Comn_StatusID], [MembershipCommiteeMemebershipNo], [MembershipCommiteeMemebershipTypeID], [PictureURL], [SignatureURL], [Comn_UniversityID], [Comn_DepartmentID], [PassingYear], [Comn_OfficeID], [Comn_BloodGroup], [PassportNo], [NationalIDNo], [BirthRegistrationID], [ExtraField1], [ExtraField2], [ExtraField3], [ExtraField4], [ExtraField5], [ExtraField6], [ExtraField7], [ExtraField8], [ExtraField9], [ExtraField10], [ExtraField11], [ExtraField12], [ExtraField13], [ExtraField14], [ExtraField15], [ExtraField16], [ExtraField17], [ExtraField18], [ExtraField19], [ExtraField20], [AddedBy], [AddedDate], [ModifiedBy], [ModifiedDate], [Comn_RowStatusID]) VALUES ( N'', 0, "+rbtnMembershipTypeNewApplicant.SelectedValue+", N'"+txtName.Text.ToUpper()+"', '"+CommonManager.DateReform(txtDOB.Text)+@"', 0, 1, N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'"+txtMobile.Text+ @"', N'', N'', N'', 1, N'', 22, CAST(0x5B950A00 AS Date), 3, 0, CAST(0x51380B00 AS Date), 0, N'', 0, N'', 0, 0, N'', 0, N'', N'', N'', N'', 0, N'', 48, 1, 0, 1, N'', N'', 0, 0, 0, 17, N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'2014032212', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', 1, GETDATE(), 1, GETDATE(), 4);
                select SCOPE_IDENTITY();
                ";
                DataSet ds= DatabaseManager.ExecSQL(sql);
                hfMem_MemberID.Value=ds.Tables[0].Rows[0][0].ToString();
                */
                loadPaymentDetails_NewMember();
                break;

            case "2":
                //Annual Fees
                dr = loadMemberInfo();
                
                loadPaymentDetailsOtherThanNewMember(dr, paidUpto);
                txtCompositionFeeForLifeFellowship.Text = "0";
                txtIDCardFee.Text = "50";
                txtDiplomaFee.Text = "0";
                calculateTotal();
                break;

            case "3":
                //Life Fees	
                dr = loadMemberInfo();
                loadPaymentDetailsOtherThanNewMember(dr, paidUpto);
                txtAnnualSubscription_Current.Text = "0";
                txtDiplomaFee.Text = "0";
                txtIDCardFee.Text = "50";
                calculateTotal();
                break;

            case "4":
                //Upgradation
                if (rbtnMembershipTypeUpGradation.SelectedValue == "")
                {
                    return;
                }

                dr = loadMemberInfo();
                loadPaymentDetailsOtherThanNewMember(dr, currentYear);
                string arrear = txtAnnualSubscription_Arrear.Text;
                dr["Mem_MemberTypeID"] = rbtnMembershipTypeUpGradation.SelectedValue;
                loadPaymentDetailsOtherThanNewMember(dr, paidUpto);
                txtCompositionFeeForLifeFellowship.Text = (ddlFeesYear.SelectedValue == "20" ? txtCompositionFeeForLifeFellowship.Text : "0");
                //txtAnnualSubscription_Current.Text = (rbtnMembershipTypeUpGradation.SelectedValue == "1" ? "600" : "300");
                txtAnnualSubscription_Arrear.Text = arrear;
                txtIDCardFee.Text = "50";
                txtDiplomaFee.Text = "100";
                calculateTotal();
                break;

            default:
                break;
        }
    }

   

    private void loadPaymentDetailsOtherThanNewMember(DataRow dr,string currentYear)
    {
        string allfeesHeadAnaAmount = CommonManager.loadFeesHistory(dr, currentYear);
        /*
                         allfeesHeadAnaAmount =
                                @"txtAnnualSubscription_Arrear_Text@" + txtAnnualSubscription_Arrear_Text
                                + "-txtAnnualSubscription_Current_Text@" + txtAnnualSubscription_Current_Text
                                + "-txtCompositionFeeForLifeFellowship_Text@" + txtCompositionFeeForLifeFellowship_Text
                                + "-txtReEnrollmentFee_Text@" + txtReEnrollmentFee_Text;
                         */
        if (allfeesHeadAnaAmount.Contains("@"))
        {
            loadValuesFromFeesTypeAndValue(allfeesHeadAnaAmount);            

        }
        else
        {
            loadOtherMessage(allfeesHeadAnaAmount);   
        }

        txtEquvalanceFee.Text = "0";
        txtAnnualSubscription_Advance.Text = (txtAnnualSubscription_Advance.Text==""?"0":txtAnnualSubscription_Advance.Text);
        txtEntranceFee.Text = "0";
    }
   
    private void loadValuesFromFeesTypeAndValue(string allfeesHeadAnaAmount)
    {
        tr_PaymentDetails.Visible = true;
            
        foreach (string item in allfeesHeadAnaAmount.Split('-'))
        {
            if (item.Split('@')[0] == "txtAnnualSubscription_Arrear_Text")
            {
                txtAnnualSubscription_Arrear.Text = item.Split('@')[1];
            }
            else if (item.Split('@')[0] == "txtAnnualSubscription_Current_Text")
            {
                txtAnnualSubscription_Current.Text = item.Split('@')[1];
            }
            else if (item.Split('@')[0] == "txtCompositionFeeForLifeFellowship_Text")
            {
                txtCompositionFeeForLifeFellowship.Text = item.Split('@')[1];
            }
            else if (item.Split('@')[0] == "txtReEnrollmentFee_Text")
            {
                txtReEnrollmentFee.Text = item.Split('@')[1];
            }
            else if (item.Split('@')[0] == "txtAnnualSubscription_Advance_Text")
            {
                txtAnnualSubscription_Advance.Text = item.Split('@')[1];
            }
        }
    }

   

    private void loadOtherMessage(string allfeesHeadAnaAmount)
    {
        if (allfeesHeadAnaAmount == "Unknown")
        {
            showAlartMessage("Please contact with Membership section to know about the last payment information");   
        }
        else if (allfeesHeadAnaAmount == "Life")
        {
            showAlartMessage("Life Member");  
        }

        tr_PaymentDetails.Visible = false;
    }
    private void showAlartMessage(string message)
    {
        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
             "err_msg",
             "alert('" + message + "');",
             true);
    }

    private DataRow loadMemberInfo()
    {
        string sql = @"
SELECT [Mem_MemberID]
      ,[MemberShipNo]
      ,[MemberShipNoDigit]
      ,[Mem_MemberTypeID]
      ,[Name]
      ,[DateOfBirth]
      ,[Age]
      ,[Comn_NationalityID]
      ,[PlaceOfBrith]
      ,[MailingAddress1]
      ,[MailingAddress2]
      ,[MailingAddress3]
      ,[MailingAddress]
      ,[PermanentAddress]
      ,[PermanentAddress1]
      ,[PermanentAddress2]
      ,[PermanentAddress3]
      ,[PhoneOffice]
      ,[PhoneResidence]
      ,[Mobile]
      ,[Email]
      ,[Fax]
      ,[OtherContactInfo]
      ,[Comn_GenderID]
      ,[PresentIEBMembershipNo]
      ,[Mem_SubDivisionID]
      ,[DeclarationDate]
      ,[Mem_ApprovedCouncilMeetingID]
      ,[ScrollNo]
      ,[ReceiptDate]
      ,[CopiesOfCertificates]
      ,[CopiesOfCertificatesComment]
      ,[CopiesOfTranscripts]
      ,[CopiesOfTranscriptsComment]
      ,[PhotoEnclosed]
      ,[ProfessionalRecordEnclosed]
      ,[ProfessionalRecordEnclosedComment]
      ,[RecomendationOffice]
      ,[RecomenDationCommentOffice]
      ,[AgeMembershipSection]
      ,[Education]
      ,[Exprerience]
      ,[RecomendationMembershipSec]
      ,[RecomenDationCommentMembershipSec]
      ,[MembershipSectionEmployeeID]
      ,[Comn_StatusID]
      ,[MembershipCommiteeMemebershipNo]
      ,[MembershipCommiteeMemebershipTypeID]
      ,[PictureURL]
      ,[SignatureURL]
      ,[Comn_UniversityID]
      ,[Comn_DepartmentID]
      ,[PassingYear]
      ,[Comn_OfficeID]
      ,[Comn_BloodGroup]
      ,[PassportNo]
      ,[NationalIDNo]
      ,[BirthRegistrationID]
      ,[ExtraField1]
      ,[ExtraField2]
      ,[ExtraField3]
      ,[ExtraField4]
      ,[ExtraField5]
      ,[ExtraField6]
      ,[ExtraField7]
      ,[ExtraField8]
      ,[ExtraField9]
      ,[ExtraField10]
      ,[ExtraField11]
      ,[ExtraField12]
      ,[ExtraField13]
      ,[ExtraField14]
      ,[ExtraField15]
      ,[ExtraField16]
      ,[ExtraField17]
      ,[ExtraField18]
      ,[ExtraField19]
      ,[ExtraField20]
      ,[AddedBy]
      ,[AddedDate]
      ,[ModifiedBy]
      ,[ModifiedDate]
      ,[Comn_RowStatusID]
  FROM [IEB].[dbo].[Mem_Member]
where MemberShipNo='" + txtMembershipNo.Text.Split('/')[0] + "/" + decimal.Parse(txtMembershipNo.Text.Split('/')[1]).ToString("00000") + @"'
";

        DataSet ds=DatabaseManager.ExecSQL(sql);
        hfMem_MemberID.Value = ds.Tables[0].Rows[0]["Mem_MemberID"].ToString();
        lblMobileNo.Text = ds.Tables[0].Rows[0]["Mobile"].ToString();
        lblName.Text = ds.Tables[0].Rows[0]["Name"].ToString();
        //imgMember.ImageUrl = "http://iebbd.org/MembersArea/MemberPicture/" + ds.Tables[0].Rows[0]["PictureURL"].ToString();
        return ds.Tables[0].Rows[0];
    }

   

    private void loadPaymentDetails_NewMember()
    {
                /*
                string sql = "";
                sql = @"INSERT [dbo].[Mem_Member] ([MemberShipNo], [MemberShipNoDigit], [Mem_MemberTypeID], [Name], [DateOfBirth], [Age], [Comn_NationalityID], [PlaceOfBrith], [MailingAddress1], [MailingAddress2], [MailingAddress3], [MailingAddress], [PermanentAddress], [PermanentAddress1], [PermanentAddress2], [PermanentAddress3], [PhoneOffice], [PhoneResidence], [Mobile], [Email], [Fax], [OtherContactInfo], [Comn_GenderID], [PresentIEBMembershipNo], [Mem_SubDivisionID], [DeclarationDate], [Mem_ApprovedCouncilMeetingID], [ScrollNo], [ReceiptDate], [CopiesOfCertificates], [CopiesOfCertificatesComment], [CopiesOfTranscripts], [CopiesOfTranscriptsComment], [PhotoEnclosed], [ProfessionalRecordEnclosed], [ProfessionalRecordEnclosedComment], [RecomendationOffice], [RecomenDationCommentOffice], [AgeMembershipSection], [Education], [Exprerience], [RecomendationMembershipSec], [RecomenDationCommentMembershipSec], [MembershipSectionEmployeeID], [Comn_StatusID], [MembershipCommiteeMemebershipNo], [MembershipCommiteeMemebershipTypeID], [PictureURL], [SignatureURL], [Comn_UniversityID], [Comn_DepartmentID], [PassingYear], [Comn_OfficeID], [Comn_BloodGroup], [PassportNo], [NationalIDNo], [BirthRegistrationID], [ExtraField1], [ExtraField2], [ExtraField3], [ExtraField4], [ExtraField5], [ExtraField6], [ExtraField7], [ExtraField8], [ExtraField9], [ExtraField10], [ExtraField11], [ExtraField12], [ExtraField13], [ExtraField14], [ExtraField15], [ExtraField16], [ExtraField17], [ExtraField18], [ExtraField19], [ExtraField20], [AddedBy], [AddedDate], [ModifiedBy], [ModifiedDate], [Comn_RowStatusID]) VALUES ( N'', 0, "+rbtnMembershipTypeNewApplicant.SelectedValue+", N'"+txtName.Text.ToUpper()+"', '"+CommonManager.DateReform(txtDOB.Text)+@"', 0, 1, N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'"+txtMobile.Text+ @"', N'', N'', N'', 1, N'', 22, CAST(0x5B950A00 AS Date), 3, 0, CAST(0x51380B00 AS Date), 0, N'', 0, N'', 0, 0, N'', 0, N'', N'', N'', N'', 0, N'', 48, 1, 0, 1, N'', N'', 0, 0, 0, 17, N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'2014032212', N'', N'', N'', N'', N'', N'', N'', N'', N'', N'', 1, GETDATE(), 1, GETDATE(), 4);
                select SCOPE_IDENTITY();
                ";
                DataSet ds= DatabaseManager.ExecSQL(sql);
                hfMem_MemberID.Value=ds.Tables[0].Rows[0][0].ToString();

                */


        switch (rbtnMembershipTypeNewApplicant.SelectedValue)
        {
            case "1":
                //Fellow
                txtAnnualSubscription_Advance.Text = "0";
                txtAnnualSubscription_Arrear.Text = "0";
                txtAnnualSubscription_Current.Text = "600";
                txtCompositionFeeForLifeFellowship.Text = "0";
                txtDiplomaFee.Text = "100";
                txtEntranceFee.Text = "400";
                txtReEnrollmentFee.Text = "0";   
                txtEquvalanceFee.Text = (chkEquivalanceFee.Checked ? "3000" : "0");
                txtIDCardFee.Text = "50";
                calculateTotal();
                break;
            case "2":
                //Member
                txtAnnualSubscription_Advance.Text = "0";
                txtAnnualSubscription_Arrear.Text = "0";
                txtAnnualSubscription_Current.Text = "350";
                txtCompositionFeeForLifeFellowship.Text = "0";
                txtDiplomaFee.Text = "100";
                txtEntranceFee.Text = "200";
                txtReEnrollmentFee.Text = "0";   
                txtEquvalanceFee.Text = (chkEquivalanceFee.Checked?"3000":"0");
                txtIDCardFee.Text = "50";
                calculateTotal();
                break;
            case "3":
                //	Associate	
                txtAnnualSubscription_Advance.Text = "0";
                txtAnnualSubscription_Arrear.Text = "0";
                txtAnnualSubscription_Current.Text = "175";
                txtCompositionFeeForLifeFellowship.Text = "0";
                txtDiplomaFee.Text = "50";
                txtEntranceFee.Text = "125";
                txtEquvalanceFee.Text = (chkEquivalanceFee.Checked?"3000":"0");
                txtReEnrollmentFee.Text = "0";   
                txtIDCardFee.Text = "50";
                calculateTotal();
                break;
            
            default:
                break;
        }
    }

    private void calculateTotal()
    {
        txtTotal.Text = (
            int.Parse(txtAnnualSubscription_Advance.Text == "" ? "0" : txtAnnualSubscription_Advance.Text)
            + int.Parse(txtAnnualSubscription_Arrear.Text == "" ? "0" : txtAnnualSubscription_Arrear.Text)
            + int.Parse(txtAnnualSubscription_Current.Text == "" ? "0" : txtAnnualSubscription_Current.Text)
            + int.Parse(txtCompositionFeeForLifeFellowship.Text == "" ? "0" : txtCompositionFeeForLifeFellowship.Text)
            + int.Parse(txtDiplomaFee.Text == "" ? "0" : txtDiplomaFee.Text)
            + int.Parse(txtEntranceFee.Text == "" ? "0" : txtEntranceFee.Text)
            + int.Parse(txtEquvalanceFee.Text == "" ? "0" : txtEquvalanceFee.Text)
            + int.Parse(txtReEnrollmentFee.Text == "" ? "0" : txtReEnrollmentFee.Text)
            + int.Parse(txtIDCardFee.Text == "" ? "0" : txtIDCardFee.Text)
            ).ToString();
    }

    private void loadReceiptType()
    {
        string currentYearValue = "17";
        switch (Request.QueryString["rbtnReceiptType"])
        {
            case "1":
                //New Applicant
                tr_NewMember.Visible = true;
                tr_not_NewMember.Visible = false;
                btnNext.Visible = true;
                break;
            case "2":
                //Annual Fees
                tr_not_NewMember.Visible = true;
                tr_NewMember.Visible = false;
                tblMembershipTypeUpgaradation.Visible = false;
                btnNext.Visible = true;
                lblPaidUpto.Visible = true;
                ddlFeesYear.Visible = true;
                ddlFeesYear.SelectedValue = currentYearValue;
                break;
            case "3":
                //	Life Fees	
                tr_not_NewMember.Visible = true;
                tr_NewMember.Visible = false;
                tblMembershipTypeUpgaradation.Visible = false;
                lblPaidUpto.Visible = false;
                ddlFeesYear.Visible = false;
                btnNext.Visible = true;
                ddlFeesYear.SelectedValue = "20";
                break;
            case "4":
                //Upgradation
                tr_not_NewMember.Visible = true;
                tr_NewMember.Visible = false;
                tblMembershipTypeUpgaradation.Visible = true;
                btnNext.Visible = true;
                lblPaidUpto.Visible = true;
                ddlFeesYear.Visible = true;
                ddlFeesYear.SelectedValue = currentYearValue;
                break;
            default:
                break;
        }
    }

    protected void btnReceiveFees_Click(object sender, EventArgs e)
    {


        ACC_JournalMaster aCC_JournalMaster = new ACC_JournalMaster();

        aCC_JournalMaster.JournalMasterName = "1";//Voucher Type
        aCC_JournalMaster.ExtraField1 = Request.QueryString["rbtnReceiptType"]=="1"?(txtName.Text+"("+hfMem_MemberID.Value+")"):(lblName.Text + "("+txtMembershipNo.Text+")");
        aCC_JournalMaster.ExtraField2 = "";
        aCC_JournalMaster.ExtraField3 = hfMem_MemberID.Value;
        aCC_JournalMaster.Note = "";
        aCC_JournalMaster.JournalDate = DateTime.Parse(CommonManager.DateReform(txtDate.Text));
        aCC_JournalMaster.AddedBy = getLogin().LoginID;
        aCC_JournalMaster.AddedDate = DateTime.Now;
        aCC_JournalMaster.UpdatedBy = getLogin().LoginID;
        aCC_JournalMaster.UpdatedDate = DateTime.Now;
        aCC_JournalMaster.RowStatusID = 1;
        int JournalMasterID = 0;
        JournalMasterID = ACC_JournalMasterManager.InsertACC_JournalMaster(aCC_JournalMaster);
        
        #region Cash in hand
		 
	
        //get Title of 
        ACC_ChartOfAccountLabel4 L4=new ACC_ChartOfAccountLabel4();
        L4 = ACC_ChartOfAccountLabel4Manager.GetACC_ChartOfAccountLabel4ByID(int.Parse(getLogin().ExtraField2));

        ACC_JournalDetail aCC_JournalDetail = new ACC_JournalDetail();

        aCC_JournalDetail.ACC_ChartOfAccountLabel4Text = L4.ChartOfAccountLabel4Text;
        aCC_JournalDetail.ACC_ChartOfAccountLabel4ID = L4.ACC_ChartOfAccountLabel4ID;

        aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Cash in Hand";//((Label)gvr.FindControl("lblACC_ChartOfAccountLabel3ID")).Text;
        aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = 1;//Int32.Parse(((HiddenField)gvr.FindControl("hfACC_ChartOfAccountLabel3ID")).Value);

        aCC_JournalDetail.JournalMasterID = JournalMasterID;
        aCC_JournalDetail.WorkStation = int.Parse(getLogin().ExtraField5);
        aCC_JournalDetail.WorkStationName = "HQ";//((Label)gvr.FindControl("lblWorkStation")).Text; ;
        aCC_JournalDetail.Debit = Decimal.Parse(txtTotal.Text);
        aCC_JournalDetail.Credit = 0;//Decimal.Parse(((Label)gvr.FindControl("lblCredit")).Text);
        aCC_JournalDetail.ExtraField3 = "";
        aCC_JournalDetail.ExtraField2 = "";
        aCC_JournalDetail.ExtraField1 ="";// ((HiddenField)gvr.FindControl("hfExtraField1")).Value;
        aCC_JournalDetail.ExtraField2 ="";// ((HiddenField)gvr.FindControl("hfExtraField2")).Value;
        aCC_JournalDetail.ExtraField3 = "";//((HiddenField)gvr.FindControl("hfExtraField3")).Value;
        aCC_JournalDetail.AddedBy = getLogin().LoginID;
        aCC_JournalDetail.AddedDate = DateTime.Now;
        aCC_JournalDetail.UpdatedBy = getLogin().LoginID;
        aCC_JournalDetail.UpdatedDate = DateTime.Now;
        aCC_JournalDetail.RowStatusID = 1;
        ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
        #endregion


        #region Membershipsubscription
		 
        L4=new ACC_ChartOfAccountLabel4();
        L4 = CommonManager.CreateChartOfAccountL4ForMember(hfMem_MemberID.Value,getLogin().LoginID);

        aCC_JournalDetail.ACC_ChartOfAccountLabel4Text = L4.ChartOfAccountLabel4Text;
        aCC_JournalDetail.ACC_ChartOfAccountLabel4ID = L4.ACC_ChartOfAccountLabel4ID;
        aCC_JournalDetail.Debit = 0;//Decimal.Parse(((Label)gvr.FindControl("lblCredit")).Text);
        
        decimal amount=CommonManager.GetDecimalValue(txtAnnualSubscription_Arrear.Text);
        if (amount != 0)
        {
            aCC_JournalDetail.ExtraField3 = "";
            aCC_JournalDetail.Credit = amount;
            aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Annual Subscription(Arrear)";
            aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtAnnualSubscription_Arrear.ToolTip);
            ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
        }
        amount=CommonManager.GetDecimalValue(txtAnnualSubscription_Advance.Text);
        if (amount != 0)
        {
            aCC_JournalDetail.ExtraField3 = "";
            aCC_JournalDetail.Credit = amount;
            aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Annual Subscription(Advance)";
            aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtAnnualSubscription_Advance.ToolTip);
            ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
        }
        amount=CommonManager.GetDecimalValue(txtAnnualSubscription_Current.Text);
        if (amount != 0)
        {
            aCC_JournalDetail.ExtraField3 = ddlFeesYear.SelectedItem.Text;
            aCC_JournalDetail.Credit = amount;
            aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Annual Subscription(Current)";
            aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtAnnualSubscription_Current.ToolTip);
            ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
        }
        amount=CommonManager.GetDecimalValue(txtCompositionFeeForLifeFellowship.Text);
        if (amount != 0)
        {
            aCC_JournalDetail.ExtraField3 = "";
            aCC_JournalDetail.Credit = amount;
            aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Composition fee for Life Fellowship";
            aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtCompositionFeeForLifeFellowship.ToolTip);
            ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
        }
         amount=CommonManager.GetDecimalValue(txtEntranceFee.Text);
         if (amount != 0)
         {
             aCC_JournalDetail.ExtraField3 = "";
             aCC_JournalDetail.Credit = amount;
             aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Entrance Fee";
             aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtEntranceFee.ToolTip);
             ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
         }
         amount=CommonManager.GetDecimalValue(txtDiplomaFee.Text);
         if (amount != 0)
         {
             aCC_JournalDetail.ExtraField3 = "";
             aCC_JournalDetail.Credit = amount;
             aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Diploma Fee";
             aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtDiplomaFee.ToolTip);
             ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
         }
         amount=CommonManager.GetDecimalValue(txtReEnrollmentFee.Text);
         if (amount != 0)
         {
             aCC_JournalDetail.ExtraField3 = "";
             aCC_JournalDetail.Credit = amount;
             aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Re-Enrollment Fee";
             aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtReEnrollmentFee.ToolTip);
             ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
         }
         amount=CommonManager.GetDecimalValue(txtEquvalanceFee.Text);
         if (amount != 0)
         {
             aCC_JournalDetail.ExtraField3 = "";
             aCC_JournalDetail.Credit = amount;
             aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "Equvalance Fee";
             aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtEquvalanceFee.ToolTip);
             ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
         }
        amount=CommonManager.GetDecimalValue(txtIDCardFee.Text);
        if (amount != 0)
        {
            aCC_JournalDetail.ExtraField3 = "";
            aCC_JournalDetail.Credit = amount;
            aCC_JournalDetail.ACC_ChartOfAccountLabel3Text = "ID Card Fee";
            aCC_JournalDetail.ACC_ChartOfAccountLabel3ID = int.Parse(txtIDCardFee.ToolTip);
            ACC_JournalDetailManager.InsertACC_JournalDetail(aCC_JournalDetail);
        }
        #endregion   
     
        #region Membership fees entry
        string sql = @"
               INSERT INTO [IEB].[dbo].[Mem_Fees]
                   ([Mem_MemberID]
                   ,[Amount]
                   ,[PaidFor]
                   ,[ExtraField]
                   ,[AddedDate]
                   ,[AddedBy]
                   ,[ModifiedBy]
                   ,[ModifiedDate]
                   ,[Comn_RowStatusID]
                   ,[RefferenceNo]
                   ,[Comn_PaymentByID]
                   ,[PaidDate]
                   ,[Mem_FeesYearID])
             VALUES
                   ((Select Mem_MemberID from  [IEB].[dbo].Mem_Member where MemberShipNo ='" + txtMembershipNo.Text + @"')--<Mem_MemberID, int,>
                   ," + txtTotal.Text + @"--<Amount, decimal(10,2),>
                   ,'" + ddlFeesYear.SelectedItem.Text + @"'--<PaidFor, nvarchar(50),>
                   ,'New Database Entry'--<ExtraField, nvarchar(256),>
                   ,GETDATE()--<AddedDate, datetime,>
                   ," +
                      getLogin().LoginID
                      + @"--<AddedBy, int,>
                   ," +
                      getLogin().LoginID
                      + @"--<ModifiedBy, int,>
                   ,GETDATE()--<ModifiedDate, datetime,>
                   ,1--<Comn_RowStatusID, int,>
                   ,'" + JournalMasterID + @"'--<RefferenceNo, nvarchar(50),>
                   ,1--<Comn_PaymentByID, int,>
                   ,'" + CommonManager.DateReformation(txtDate.Text) + @"'--<PaidDate, datetime,>
                   ," + ddlFeesYear.SelectedValue + @"--<Mem_FeesYearID, int,>
                    );
            Select top 1 Mem_FeesID from [IEB].[dbo].[Mem_Fees] order by Mem_FeesID desc
                ";
       DataSet ds= DatabaseManager.ExecSQL(sql);
       btnReceiveFees.Visible = false;
       lblPrint.Text = "<a target='_blank' href='MembershipFeesReceipt.aspx?Mem_FeesID="+ds.Tables[0].Rows[0][0].ToString()+@"'>Print</a>";
        #endregion
    }

    
    protected void rbtnMembershipTypeNewApplicant_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnNext_Click(this,new EventArgs());
    }
    protected void rbtnMembershipTypeUpGradation_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnNext_Click(this, new EventArgs());
    }
    protected void chkEquivalanceFee_CheckedChanged(object sender, EventArgs e)
    {
        btnNext_Click(this, new EventArgs());
    }
    protected void ddlFeesYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        btnNext_Click(this, new EventArgs());
    }
}